/*
 * @lc app=leetcode id=500 lang=cpp
 *
 * [500] Keyboard Row
 */

// @lc code=start
class Solution {
public:
    vector<string> findWords(vector<string>& words) {
        int w[128] = {0};
        std::vector<std::string> vs = {"qwertyuiop", "asdfghjkl", "zxcvbnm"};
        for (int i = 0; i < vs.size(); ++i) {
            for (auto c : vs[i]) {
            w[c] = i + 1;
            w[c - 32] = i + 1;
            }
        }
        std::vector<std::string> res;
        for (auto &word : words) {
            int ans = w[word[0]];
            bool flag = true;
            for (auto c : word) {
            if (w[c] != ans){
                flag = false;
                break;
            }
            }
            if (flag) {
                res.push_back(word);
            }

        }
        return res;
    }
};
// @lc code=end

